// 深拷贝
export const deepCopy = (obj, cache = new Map()) => {
  if (typeof obj === 'object' && obj !== null) {
    if (cache.has(obj)) {
      return cache.get(obj);
    }
    if (obj instanceof Date) {
      return new Date(obj.getTime());
    }
    if (obj instanceof RegExp) {
      return new RegExp(obj);
    }
    if (typeof obj === 'function') {
      const funcStr = obj.toString();
      let func;
      try {
        func = eval(`(${funcStr})`);
      } catch (e) {
        func = Function(`return ${funcStr}`)();
      }
      cache.set(obj, func);
      return func;
    }
    let copy = Array.isArray(obj) ? [] : {};
    cache.set(obj, copy);
    for (let key in obj) {
      copy[key] = deepCopy(obj[key])
    }
    return copy;
  }
  return obj;
}